package com.gpjcjl.adapter;

import android.content.Context;

import com.zhy.adapter.recyclerview.CommonAdapter;

import java.util.Collection;
import java.util.List;

public abstract class BaseRecyclerAdapter<T> extends CommonAdapter<T> {

    public BaseRecyclerAdapter(Context context, int layoutId, List<T> datas) {
        super(context, layoutId, datas);
    }

    public void addList(Collection<T> data) {
        if (data == null) {
            return;
        }
        mDatas.addAll(data);
        notifyDataSetChanged();
    }

    /**
     * 添加集合
     *
     * @param data    对象集合
     * @param refresh 是否刷新（需要清空）
     */
    public void addList(Collection<T> data, boolean refresh) {
        if (data == null) {
            return;
        }
        if (refresh) {
            mDatas.clear();
        }
        mDatas.addAll(data);
        notifyDataSetChanged();
    }

    public void clear() {
        mDatas.clear();
        notifyDataSetChanged();
    }

    public T getItem(int index) {
        return mDatas.get(index);
    }

    public boolean isEmpty() {
        return mDatas.size() == 0;
    }

}
